from enum import Enum, unique


@unique
class ErrorCodeEnum(Enum):
    SUCCESS = 200
    ADD_JOB_FAIL = 1001
    ALREADY_HANDLED = 1002
    DATA_IS_NOT_EXIST = 1003
    REQUEST_PARAM_MISSED = 1004
    EQUEST_PARAM_FORMAT_ERROR = 1005
    SERVER_IS_BUSY = 1006
    JOB_RESULT_ADD_FAIL = 1007
    JOB_STATUS_UPDATE_FAIL = 1008
    NOT_FOUND = 404
    BAD_REQUEST = 400
    FORBIDDEND = 403


class responseCode(object):

    @property
    def SUCCESS(self):
        return {'code': 200, 'msg': '请求成功', 'data': None}

    @property
    def ADD_JOB_FAIL(self):
        return {'code': 1001, 'msg': '添加任务失败', 'data': None}

    @property
    def ALREADY_HANDLED(self):
        return {'code': 1002, 'msg': '参数类型错误', 'data': None}

    @property
    def DATA_IS_NOT_EXIST(self):
        return {'code': 1003, 'msg': '数据不存在', 'data': None}

    @property
    def REQUEST_PARAM_MISSED(self):
        return {'code': 1004, 'msg': '请求参数缺失', 'data': None}

    @property
    def REQUEST_PARAM_FORMAT_ERROR(self):
        return {'code': 1005, 'msg': '请求参数格式错误', 'data': None}

    @property
    def SERVER_IS_BUSY(self):
        return {'code': 1006, 'msg': '服务器繁忙，请稍后添加', 'data': None}

    @property
    def JOB_RESULT_ADD_FAIL(self):
        return {'code': 1007, 'msg': '添加任务结构失败', 'data': None}

    @property
    def JOB_STATUS_UPDATE_FAIL(self):
        return {'code': 1008, 'msg': '任务结果更新失败', 'data': None}

    @property
    def NOT_FOUND(self):
        return {'code': 404, 'msg': 'HTTP 404 Not Found', 'data': None}

    @property
    def BAD_REQUEST(self):
        return {'code': 400, 'msg': 'HTTP 400 Bad Request', 'data': None}

    @property
    def FORBIDDEND(self):
        return {'code': 403, 'msg': 'HTTP 403 Forbidden', 'data': None}

    def get_struct_by_error_code(self, error_code):
        if error_code == ErrorCodeEnum.SUCCESS:
            return self.SUCCESS
        if error_code == ErrorCodeEnum.ADD_JOB_FAIL:
            return self.ADD_JOB_FAIL
        if error_code == ErrorCodeEnum.ALREADY_HANDLED:
            return self.ALREADY_HANDLED
        if error_code == ErrorCodeEnum.DATA_IS_NOT_EXIST:
            return self.DATA_IS_NOT_EXIST
        if error_code == ErrorCodeEnum.REQUEST_PARAM_MISSED:
            return self.REQUEST_PARAM_MISSED
        if error_code == ErrorCodeEnum.REQUEST_PARAM_FORMAT_ERROR:
            return self.REQUEST_PARAM_FORMAT_ERROR
        if error_code == ErrorCodeEnum.SERVER_IS_BUSY:
            return self.SERVER_IS_BUSY
        if error_code == ErrorCodeEnum.JOB_RESULT_ADD_FAIL:
            return self.JOB_RESULT_ADD_FAIL
        if error_code == ErrorCodeEnum.JOB_STATUS_UPDATE_FAIL:
            return  self.JOB_STATUS_UPDATE_FAIL
        if error_code == ErrorCodeEnum.NOT_FOUND:
            return self.NOT_FOUND
        if error_code == ErrorCodeEnum.BAD_REQUEST:
            return self.BAD_REQUEST
        if error_code == ErrorCodeEnum.FORBIDDEND:
            return self.FORBIDDEND


response_code = responseCode()
